home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer: Getting Started / Internet Surfer - Getting Started (Wayzata Technology)(7231)(1995).bin / pc / mac / bonus / peter_le / dehqx-20 / mynotifi.uni < prev    next >
Text File  |  1991-08-23  |  4KB  |  173 lines

  1. unit MyNotifier;
  2. { DeHQX v2.0.0 ⌐ Peter Lewis, Aug 1991 }
  3.  
  4. { Derived from <jholt@adobe.COM> Joe Holt's StartupError code as posted }
  5. { to comp.sys.mac.programmer May 1991 }
  6.  
  7. { Notification Manager messages }
  8.  
  9. { History: }
  10. {   jhh 18 jun 90 -- response to news posting }
  11. {   pnl 29 may 91 -- Converted to pascal to be used in an application }
  12.  
  13. interface
  14.  
  15.     uses
  16.         Notification;
  17.  
  18.     procedure InitNotify;
  19.     procedure FinishNotify;
  20.     procedure Notify (mark, sound: boolean; sicn_id, sicn_index, str_id, str_index: integer);
  21. { mark - mark the current application }
  22. { sound - play sysbeep }
  23. { sicn_id, sicn_index - SICN id to rotate with the apple & index (<1 -> 1)   OR 0&0 for no sicn }
  24. { str_id, str_index - STR# id & index    OR    STR id & 0    OR    0 & 0 }
  25.     procedure NotifyCompletion;
  26. { Call this when in event loop when in the foreground to remove apple mark and flash }
  27.  
  28. implementation
  29.  
  30.     const
  31.         sicn_size = 32;
  32.         T_NMInstall = $A05E;
  33.         T_Unimplemented = $A89F;
  34.  
  35.     type
  36.         NMRecPtrPtr = ^NMRecPtr;
  37.         booleanPtr = ^boolean;
  38.  
  39.     var
  40.         current_note: NMRecPtr;
  41.         notify_finished: boolean;
  42.  
  43. { handles must be non-purgeable, but may be unlocked }
  44.  
  45.     procedure InitNotify;
  46.     begin
  47.         current_note := nil;
  48.         notify_finished := false;
  49.     end;
  50.  
  51.     procedure MyResponse (note: NMRecPtr);
  52.     begin
  53.         booleanPtr(note^.nmRefCon)^ := true;
  54.     end;
  55.  
  56.     procedure UnNotify;
  57.         var
  58.             oe: OSErr;
  59.     begin
  60.         if current_note <> nil then begin
  61.             oe := NMRemove(current_note);
  62.             with current_note^ do begin
  63.                 if nmStr <> nil then
  64.                     DisposPtr(pointer(nmStr));
  65.                 if nmIcon <> nil then
  66.                     DisposHandle(nmIcon);
  67.             end;
  68.             DisposPtr(pointer(current_note));
  69.             current_note := nil;
  70.         end;
  71.         notify_finished := false;
  72.     end;
  73.  
  74.     procedure NotifyCompletion;
  75.     begin
  76.         if notify_finished then
  77.             UnNotify;
  78.     end;
  79.  
  80.     procedure FinishNotify;
  81.     begin
  82.         if current_note <> nil then
  83.             UnNotify;
  84.     end;
  85.  
  86.     procedure Notify (mark, sound: boolean; sicn_id, sicn_index, str_id, str_index: integer);
  87.         var
  88.             errorText: str255;
  89.             sh: stringHandle;
  90.             sicnH: handle;
  91.             error: boolean;
  92.             oe: OSErr;
  93.     begin
  94.         UnNotify;            { Clear outstanding notify }
  95.         if NGetTrapAddress(T_NMInstall, OSTrap) = NGetTrapAddress(T_Unimplemented, ToolTrap) then begin
  96.             SysBeep(1);   { Best we can do I guess.  Could put up the dialog box maybe?...}
  97.         end
  98.         else begin
  99.             current_note := NMRecPtr(NewPtr(sizeof(NMRec)));
  100.             if current_note = nil then begin
  101.                 SysBeep(1);   { Can't do much else if there isnt even room for this! }
  102.             end
  103.             else begin
  104.                 with current_note^ do begin
  105.                     qType := nmType;
  106.                     error := false;
  107.                     booleanPtr(nmRefCon) := @notify_finished;
  108.                     if mark then
  109.                         nmMark := 1
  110.                     else
  111.                         nmMark := 0;
  112.                     nmStr := nil;
  113.                     if str_id <> 0 then begin
  114.                         if str_index > 0 then
  115.                             GetIndString(errorText, str_id, str_index)
  116.                         else begin
  117.                             errorText := '';
  118.                             sh := GetString(str_id);
  119.                             if sh <> nil then begin
  120.                                 if sh^ <> nil then
  121.                                     errorText := sh^^;
  122.                                 ReleaseResource(handle(sh));
  123.                             end;
  124.                         end;
  125.                         if errorText = '' then
  126.                             error := true
  127.                         else begin
  128.                             nmStr := stringPtr(NewPtr(length(errorText) + 1));
  129.                             if nmStr = nil then
  130.                                 error := true
  131.                             else
  132.                                 nmStr^ := errorText;
  133.                         end;
  134.                     end;
  135.                     nmIcon := nil;
  136.                     if sicn_id <> 0 then begin
  137.                         if sicn_index < 1 then
  138.                             sicn_index := 1;
  139.                         sicn_index := (sicn_index - 1) * sicn_size;   { 1-based, like STR# }
  140.                         sicnH := GetResource('SICN', sicn_id);
  141.                         HNoPurge(sicnH);
  142.                         if sicnH = nil then
  143.                             error := true
  144.                         else begin
  145.                             nmIcon := NewHandle(sicn_size);
  146.                             if nmIcon = nil then
  147.                                 error := true
  148.                             else if nmIcon^ = nil then
  149.                                 error := true
  150.                             else if GetHandleSize(sicnH) < sicn_index + sicn_size then
  151.                                 error := true
  152.                             else begin
  153.                                 BlockMove(ptr(longInt(sicnH^) + sicn_index), nmIcon^, sicn_size);
  154.                             end;
  155.                             ReleaseResource(sicnH);
  156.                         end;
  157.                     end;
  158.                     if sound or error then
  159.                         nmSound := handle(-1)
  160.                     else
  161.                         nmSound := nil;
  162.                     nmResp := @MyResponse;
  163.                 end;
  164.                 oe := NMInstall(current_note);
  165.                 if oe <> noErr then begin
  166.                     current_note := nil;
  167.                     SysBeep(1);
  168.                 end;
  169.             end;
  170.         end;
  171.     end;
  172.  
  173. end.